
<div id="finance-analysis" style="width: 1200px; height: 600px"></div>
<script type="text/javascript">

    var ctx;
    var option = {
        title: {
            text: '平台财务收支明细'
        },
        tooltip : {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        legend: {
            data:[]
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                data : []
            }
        ],
        dataZoom: [{
            type: 'inside',
            start: 50,
            end: 100
        }, {
            start: 0,
            end: 10,
            handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
            handleSize: '80%',
            handleStyle: {
                color: '#fff',
                shadowBlur: 3,
                shadowColor: 'rgba(0, 0, 0, 0.6)',
                shadowOffsetX: 2,
                shadowOffsetY: 2
            }
        }],
        yAxis : [
            {
                type : 'value',
                boundaryGap: [0, '100%']
            }
        ],
        series : []
    };
    // 指定图表的配置项和数据
    var seriesOptions = function (name, data) {
        return  {
            name:name,
            type:'line',
            areaStyle: {normal: {}},
            data:data
        }
    };

    // 使用刚指定的配置项和数据显示图表。

    function setFinanceLineOption(postData) {
        var series = [];
        var legend = [];
        $.get('{{route('api.order.chart.finance')}}', postData, function (data) {
            if (data.code == 0) {
                var resData = data.data;
                option.xAxis[0].data = resData.xAxis;
                legend = resData.lineProperty;
                var len = legend.length;
                var resSeries = resData.series;
                for (var i =0; i< len; i++) {
                    var name = legend[i];
                    series.push(seriesOptions(name, resSeries[name]));
                }
                option.series = series;
                option.legend.data = legend;
                ctx.setOption(option);
            }
        });
        // return option;

    }

    $(function() {
        var finance_chat = document.getElementById('finance-analysis');
        ctx = echarts.init(finance_chat);
        myChartContainer(finance_chat);
        $(window).resize(function () {
            myChartContainer(finance_chat);
            ctx.resize();
        });
        setFinanceLineOption(defaultData);
    });



</script>
